﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace FlexLib.RegistryTree
{
	public class RegTreeKey
	{
		public RegTreeKey(string name)
		{
			this.name = name;
		}

		private string name;
		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		private List<RegTreeKey> subKeys = new List<RegTreeKey>();
		public List<RegTreeKey> SubKeys
		{
			get { return subKeys; }
			set { subKeys = value; }
		}

		public void AddKey(RegTreeKey key)
		{
			if (this == null)
			{
				MessageBox.Show("ZLO");
			}
			subKeys.Add(key);
			key.parent = this;
		}

		public RegTreeKey AddKey(string name)
		{
			RegTreeKey key = new RegTreeKey(name);
			AddKey(key);
			return key;
		}

		public void RemoveKey(RegTreeKey key)
		{
			subKeys.Remove(key);
		}

		public void ClearKeys()
		{
			subKeys.Clear();
		}

		public void Clear()
		{
			ClearKeys();
			ClearProperties();
		}

		private List<RegProperty> properties = new List<RegProperty>();
		public List<RegProperty> Properties
		{
			get	{ return properties; }
		}

		public void AddProperty(RegProperty property)
		{
			properties.Add(property);
		}

		public void AddProperty(string name, string value, FlexLib.RegistryTree.RegProperty.RegValueType type)
		{
			properties.Add(new RegProperty(name, value, type));
		}

		public void RemoveProperty(RegProperty property)
		{
			properties.Remove(property);
		}

		public void ClearProperties()
		{
			properties.Clear();
		}

		public void Remove()
		{
			if (this.parent != null)
				this.parent.RemoveKey(this);
		}

		private RegTreeKey parent = null;
		public RegTreeKey Parent
		{
			get { return parent; }
		}

		public string GetFullPath()
		{
			string path = "";
			if (parent != null)
			{
				path = parent.GetFullPath() + "\\";
			}

			return path + this.name;
		}		
	}
}
